/*
 * Task.h
 *
 *  Created on: 2020-09-01
 *      Author: Administrator
 */

#ifndef TASK_TASK_H_
#define TASK_TASK_H_

#include "SysCommon.h"

#define TASK_TOTAL_NUM      9

#define CURRENT_TASK_INDEX   Task_GetCurrentTaskIndex()

#define TASK_RUNCNT_MAX    (0xFFFF)

typedef void(*TaskFunc)(void);

typedef struct
{
	uint8_t u8TaskEnFlag;
	uint8_t u8TaskRunFlag;
	uint8_t u8RunCntLmtFlag;
	uint32_t u32DelayTime;
	uint32_t u32CycleTime;
	uint16_t u16RunCnt;
	uint16_t u16RunCntMax;
	TaskFunc pfTaskFunc;
	TaskFunc pfTaskStartCallBack;
	TaskFunc pfTaskStopCallBack;
}TaskCB_T;


typedef TaskCB_T  UserTaskConfig_T;


#define TASKCB_INIT_VAL       {DISABLE, DISABLE, DISABLE, 0, 0, 0, 0, NULL, NULL, NULL}


extern TaskCB_T  g_stTaskList[TASK_TOTAL_NUM];

extern uint16_t Task_GetRunCnt(uint8_t u8Taskindex);

extern uint8_t  Task_GetTaskEnFlag(uint8_t u8Taskindex);

extern uint8_t  Task_GetCurrentTaskIndex(void);

extern uint16_t Task_GetCurrentTaskRunCnt(void);

extern void Task_ClearCurrentTaskRunCnt(void);

extern void Task_SetCurrTaskTime(uint32_t u32DelayTime, uint32_t u32CycleTime, uint8_t u8TaskEnable);

extern void Task_StopTask(uint8_t u8Taskindex);

extern void Task_SetTaskTime(uint8_t u8Taskindex, uint32_t u32Delaytime, uint32_t u32Cycletime);

extern void Task_StartTaskWithoutLmt(uint8_t u8Taskindex, uint32_t u32Delaytime, uint32_t u32Cycletime);

extern void Task_StartTaskWithLmt(uint8_t u8Taskindex, uint32_t u32Delaytime, uint32_t u32Cycletime, uint16_t u16Runcntmax);

extern void Task_StopSchedule(void);

extern void Task_StartSchedule(void);

extern void Task_TimeTick(void);

extern void Task_Schedule(void);

extern void Task_Init(const UserTaskConfig_T* puserTaskCfgs, uint8_t u8taskNums);

#endif /* TASK_TASK_H_ */
